import os
file_name=input('请输入需要恢复的文件名字')
file_hash_name=file_name +'_hash'
base_path="D:/PythonProject1"
def recovering():
    data=str()
    global file_name
    if os.path .isfile(file_hash_name):
        dir=input("请输入你想恢复到的目录（默认当前目录）")
        dir_file=dir+file_name
        with open(file_hash_name   ,'r')as f:

            for line in f:
                hash_value=str(line.strip())
                hash_dir = [hash_value[i * 2:(i + 1) * 2] for i in range(2)]
                file_name = hash_value[4:]
                hash_rel_dir = os.path.join(base_path, *hash_dir)
                file_rel_path = os.path.join(hash_rel_dir, file_name)
                with open(file_rel_path ,'r')as hf:
                    data+=hf.read()
        with open(dir_file ,'w')as df:
            df.write(data)


recovering()